package com.destination.model;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;


public class ConnUtil {
	
	//远程服务器地址
	public static String server="http://192.168.1.104:8080/AndroidWebserver";
	public static HttpClient hc =null;
	
	public ConnUtil(){
		hc = new HttpClient();
	}
	
	//获取远程数据的教室列表信息
	public String getDisClassroomsInfo(int currentPage,int lineSize){
		return getDisInfomation("classrooms", currentPage+","+lineSize);
	}
	
	//获取远程数据的教室总数信息
	public String getDisClassroomsCountInfo(){
		return getDisInfomation("classrooms", "count");
	}
	
	//获取远程的课程列表信息
	public String getDisLessonSersInfo(){
		return getDisInfomation("lessonsers", "lessonsers");
	}
	
	
	//获取远程的指定的课程列表中的课程的信息
	public String getDisLessonInfo(String lessonSer_id){
		
		return getDisInfomation("lesson", lessonSer_id);
	}
	
	//获取远程的教室的状态信息
	public String getDisClassstateInfo(){
		return getDisInfomation("classstate", "classstate");
	}
	
	//远程访问服务器数据内容
	public String getDisInfomation(String action,String content){
		PostMethod postMethod = new PostMethod(server+"/androidaction/"+action+".action");
		postMethod.setParameter(action,content);
		
		String str="";
		try {
			hc.executeMethod(postMethod);
			str= postMethod.getResponseBodyAsString();
		} catch (IOException e) {
			e.printStackTrace();
		}
		finally
		{
			postMethod.releaseConnection();
		}
		return str;
	}
}
